﻿@model App.Models.Games

@{
	ViewBag.Title = "Gleðiðland.is - " + Model.GameType;
}

<h2>@Model.GameType</h2>

<table id="tictactoe">
	<tbody>
		<tr>
			<td id="cell1">&nbsp;</td>
			<td id="cell2">&nbsp;</td>
			<td id="cell3">&nbsp;</td>
		</tr>
		<tr>
			<td id="cell4">&nbsp;</td>
			<td id="cell5">&nbsp;</td>
			<td id="cell6">&nbsp;</td>
		</tr>
		<tr>
			<td id="cell7">&nbsp;</td>
			<td id="cell8">&nbsp;</td>
			<td id="cell9">&nbsp;</td>
		</tr>
	</tbody>
</table>

<script>
	$(function () {
		var group = '@(Model.GamesID)';
		var hub = $.connection.tttGameHub;

		hub.client.cellClicked = function (cellId) {
			$("#" + cellId).text("O");
		};

		$.connection.hub.start().done(function() {
			hub.server.join(group);
			//getum notað ajax í stðain fyrir að kalla á server
			$("#tictactoe tr td").click(function () {
				hub.server.clickCell(group, this.id);
				$(this).text("X");
			});
		});
	});

</script>